package org.minuframework.file.upload;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.minuframework.lang.StringUtils;
import org.minuframework.utils.ParamUtils;
import org.minuframework.file.FileReader;
import org.minuframework.lang.ArrayUtils;

/**
 * 文件格式类
 * @author 米mi
 */
@Deprecated
public class FileTypesConfigurer{
    
    private File                file;
    private Map<Object, Object> params;
    
    /**
     * 常见图片格式
     */
    private static final String[] imgArray = {".ai" ,".bmp" ,".cdr" ,"dxf" ,".eps" ,".emp" ,".exif" ,".fpx" ,".flic" ,".gif" ,".ico" ,
            ".jpg" ,".pcx" ,".png" ,".psd" ,".pcd" ,".raw" ,".svg" ,".tga" ,".tiff" ,".ufo" ,".wmf" ,".webp"};
    
    /**
     * 常见视频格式
     */
    private static final String[] videoArray = {".avi" ,"asf" ,".dat" ,".flv" ,".f4v" ,".mts" ,".mov" ,".mkv" ,".m4v" ,".mpg" ,".mp4" ,
            ".m2ts" ,".mpeg" ,".mpeg-1" ,".mpeg-2" ,".navi" ,".ram" ,".rmvb" ,".ts" ,".tp" ,".qsv" ,".wmv" ,".webm" ,".vob" ,".3gp"};
    
    /**
     * 常见音频格式
     */
    private static final String[] audioArray = {".au" ,".aac" ,".amr" ,".ape" ,".aiff" ,".flac" ,".mid" ,".mp1" ,".mp2" ,".mp3" ,".mepg-4" ,
            ".ogg" ,".ra" ,".rm" ,".rmx" ,".vqf" ,".wav" ,".wma"};
    
    /**
     * 常见文档格式
     */
    private static final String[] docArray = {".brm" ,".chm" ,".csv" ,".dbf" ,".dif" ,".doc" ,".dot" ,".docx" ,".dotx" ,".docm" ,".dotm" ,
            ".et" ,".ett" ,".htm" ,".html" ,".mht" ,".mhtml" ,".txt" ,".jar" ,".pdb" ,".pdf" ,"pdg" ,".ppt" ,".prn" ,".rtf" ,".umd" ,
            ".wdl" ,".wps" ,".wpt" ,".xls" ,".xlt" ,".xlsx" ,".xlsm" ,".xltx" ,".xltm" ,".xml"};
    
    /**
     * 压缩包格式
     */
    private static final String[] zipArray = {".arj" ,".ace" ,".alz" ,".bz" ,".bz2" ,".bzip2" ,".cba" ,".cpio" ,".deb" ,".dmg" ,".gz" ,
            ".gzip" ,".hfs" ,".iso" ,".img" ,".isz" ,".jar" ,".lzh" ,".lzma" ,".lzma86" ,".rar" ,".rpm" ,".swm" ,".split" ,".tar" ,".taz" ,
            ".tgz" ,".tpz" ,".txz" ,".tbz" ,".tbz2" ,".uue" ,".xz" ,".xar" ,".xpi" ,".wim" ,".z" ,".zip" ,"zipx" ,".001" ,".7z"};
    
    public FileTypesConfigurer(File file){
        this.file = file;
    }
    
    public Map<Object, Object> getParamerRepositiry(){
        if (params == null) {
            params = FileReader.asMap(file);
        }
        return params;
    }
    
    /**
     * 根据文件后缀获取文件content_type
     * @param suffix 后缀名 String
     * @return content_type String
     */
    public String getContentType(String fileName){
        StringBuilder result = new StringBuilder();
        if (StringUtils.isNotEmpty(fileName)) {
            String suffix = ParamUtils.suffix(fileName);
            if (getParamerRepositiry().containsKey(suffix)) {
                result.append(getParamerRepositiry().get(suffix).toString());
            }
        }
        return result.toString();
    }
    
    /**
     * 检测是否为图片格式
     * @param suffix 后缀名 String
     * @return boolean
     */
    public boolean isImage(String suffix){
        boolean flag = false;
        if (StringUtils.isEmpty(suffix)) { return flag; }
        List<Object> list = ArrayUtils.asList(imgArray);
        flag = list.contains(suffix);
        return flag;
    }
    
    /**
     * 检测是否为视频格式
     * @param suffix 后缀名 String
     * @return boolean
     */
    public boolean isVideo(String suffix){
        boolean flag = false;
        if (StringUtils.isEmpty(suffix)) { return flag; }
        List<Object> list = ArrayUtils.asList(videoArray);
        flag = list.contains(suffix);
        return flag;
    }
    
    /**
     * 检测是否为视频格式
     * @param suffix 后缀名 String
     * @return boolean
     */
    public boolean isAudio(String suffix){
        boolean flag = false;
        if (StringUtils.isEmpty(suffix)) { return flag; }
        List<Object> list = ArrayUtils.asList(audioArray);
        flag = list.contains(suffix);
        return flag;
    }
    
    /**
     * 检测是否为文档
     * @param suffix 后缀名 String
     * @return boolean
     */
    public boolean isDoc(String suffix){
        boolean flag = false;
        if (StringUtils.isEmpty(suffix)) { return flag; }
        List<Object> list = ArrayUtils.asList(docArray);
        flag = list.contains(suffix);
        return flag;
    }
    
    /**
     * 检测是否为压缩包
     * @param suffix 后缀名 String
     * @return boolean
     */
    public boolean isZip(String suffix){
        boolean flag = false;
        if (StringUtils.isEmpty(suffix)) { return flag; }
        List<Object> list = ArrayUtils.asList(zipArray);
        flag = list.contains(suffix);
        return flag;
    }
    
}
